<?php
class Admin_Form_ValidateNewsItem extends Zendvn_Validate_Form{

	public function __construct($arrParam = null, $options = null){
		
		define('NAME_ID',@$arrParam['id']);
		$config = new Zendvn_Controller_Config(array('module'=>$arrParam['module'],
												'fileConfig'=>'validates/news-item.ini'));
		if($arrParam['action']=='edit'){
			$config = new Zendvn_Controller_Config(array('module'=>$arrParam['module'],
					'fileConfig'=>'validates/news-item.ini',
					'section'=>'edit'));
		}
		//================================Validate Name================================
		$name  = $config->getConfig('full_name');
		$validator  =  $this->validate($name,$arrParam);
		if(!$validator->isValid($arrParam['full_name'])){
			$message = $validator->getMessages();
			$this->_arrError['full_name'] = current($message);
			$arrParam['full_name'] = '';
		}

		$name  = $config->getConfig('email');
		$validator  =  $this->validate($name,$arrParam);
		if(!$validator->isValid($arrParam['email'])){
            if(empty($arrParam['email'])){
                $message = current($validator->getMessages());

            }else{
                $message = $arrParam['email'].' is a duplicate entry. An entry with this email already exists';
            }

			$this->_arrError['email'] = 'Email: '.($message);
			$arrParam['email'] = '';
		}

		$name  = $config->getConfig('website');
		$validator  =  $this->validate($name,$arrParam);
		if(!$validator->isValid($arrParam['website'])){
            if(empty($arrParam['website'])){
                $message = current($validator->getMessages());

            }else{
                $message = $arrParam['website'].' is a duplicate entry. An entry with this web address already exists';
            }
			$this->_arrError['website'] = 'Website: '.($message);
			$arrParam['website'] = '';
		}

		if(empty($arrParam['cat_id'])){
			$this->_arrError['cat_id'] = 'Please select a category!';
		}

		$this->_arrData = $arrParam;
	}
	
	public function getData(){

		return $this->_arrData;
	}
	//return true|false
	public function isVaild(){
		$flag = false;
		if(count($this->_arrError) > 0 && $this->_arrError != ''){
			$flag = true;
		}
		return $flag;
	}
	
	public function getMessageErrors(){
		return $this->_arrError;
	}
	

}







